package mfuny.ggongal.admin.https;

import java.net.URLDecoder;
import java.util.HashMap;

public class GGDecoder {
	static String pinErrMsg = "pin error!";
	
	public static String decode(String bStr) throws Exception {
		bStr = URLDecoder.decode(bStr, "UTF-8");
		
		Neutral neu = new Neutral();
		bStr = neu.lastTurnOver(bStr);
		HashMap<String, Object> resultMap = neu.separateStr(bStr);
		
		String pinStr = (String)resultMap.get("pin");
		int pin = Integer.parseInt(pinStr.substring(0, 2));
		pinStr = pinStr.substring(2);
		String ope2h = neu.getOpe2h()[pin];
		if( !pinStr.equals(ope2h) ) {
			return pinErrMsg;
		}
		
		String main = (String)resultMap.get("main");
		main = neu.rollback(main);
		main = neu.ternOver(main);
		main = neu.rollback(main);
		
		return main;
	}
}
